package learn.vilen.com.learnapidemos;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import learn.vilen.com.learnapidemos.app.HelloWorld;

public class ApiDemos extends ListActivity {
  // private final String TAG = "ApiDemos";

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
    Map<String, Object> map = new HashMap<>();
    map.put("title", "Accessibility");
    data.add(map);
    Map<String, Object> map2 = new HashMap<>();
    map2.put("title", "Animation");
    data.add(map2);
    Map<String, Object> map3 = new HashMap<>();
    map3.put("title", "App");
    data.add(map3);
    Map<String, Object> map4 = new HashMap<>();
    map4.put("title", "HelloWorld");
    map4.put("intent", new Intent(this,HelloWorld.class));
    data.add(map4);
    setListAdapter(
        new SimpleAdapter(this, data, android.R.layout.simple_list_item_1, new String[] {"title"},
            new int[] {android.R.id.text1}));
    getListView().setTextFilterEnabled(true);
  }

  @Override protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Map map = (Map) l.getItemAtPosition(position);
    if(position == 3) {
      Intent intent = (Intent)map.get("intent");
      startActivity(intent);
    }
  }
}
